package com.bw.module_staff.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.module_staff.entity.StaffEntity
import com.bw.module_staff.repo.StaffRepo
import kotlinx.coroutines.launch

/**
 * 工单-智慧园区-人员管理
 */

class StaffViewModel :BaseViewModel2<StaffRepo>(){
    val staffSuccess by lazy { MutableLiveData< List<StaffEntity>>() }

    fun getStaff(){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.getStaff()
            if (result.code == 200){
                staffSuccess.postValue(result.data)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }

    val addStaffSuccess = MutableLiveData<StaffEntity>()

    fun addStaff(staffEntity: StaffEntity){
        CoroutineHelper.mViewModelScope.launch(CoroutineHelper.mDispatcher){
            val result = mRepository.addStaff(staffEntity)
            if (result.code == 200){
                addStaffSuccess.postValue(result.data!!)
            } else {
                mErrorLiveData.postValue("数据异常！！")
            }
        }
    }

    override fun createRepository(): StaffRepo = StaffRepo()

}